import { defineStore } from "pinia";
import { storage } from "../save";
export const infoStore = defineStore({
  id: "info",
  state: () => {
    let verify: string[] = [];
    // BUG 初始化用户权限，生产模式下换成将下面的一行注释掉
    verify = ["0", "1", "2", "3", "-1"];
    try {
      JSON.parse(storage.getItem("verify") || "");
    } catch (error) {}
    if (!Array.isArray(verify)) verify = [];
    return {
      verify: [...verify],
      nickname: storage.getItem("nickname") || "用户名",
    };
  },
  actions: {
    setVerify({ verify = 0 }: { verify: number }) {
      console.log(verify);
      
      const qx = [
        null /* 未登录 */,
        ["0", "1"] /* 长期客户 */,
        ["0", "1", "2", "-1"] /* 操作员 */,
        ["0", "1", "2", "3", "-1"] /* 网站管理员 */,
        ["0", "-1"] /* 观察员 */,
      ];
      storage.setItem("verify", JSON.stringify(qx[verify]));
      this.verify = qx[verify] || [];
    },
    setNickname({ nickname = "未命名" }: { nickname: string }) {
      storage.setItem("nickname", nickname);
      this.nickname = nickname;
    },
  },
});
